clear all
clf
hold off
set(gcf,'color','w')
colormap(parula(100))
axis off
format long
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Distrib gains
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

addpath('...\replication\altmany-export_fig-d570645');

Y_n = load('...\replication\Section 6\01_data\res_Y_n.csv');
Y_i = load('...\replication\Section 6\01_data\res_Y_i.csv');
L_i = load('...\replication\Section 6\01_data\res_L_i.csv');
R_n = load('...\replication\Section 6\01_data\res_R_n.csv');
w_i = load('...\replication\Section 6\01_data\res_w_i.csv');
v_n = load('...\replication\Section 6\01_data\res_v_n.csv');


gr_Y_i = 100.*((Y_i(:,4) - Y_i(:,1))./(Y_i(:,1)));
gr_Y_n = 100.*((Y_n(:,4) - Y_n(:,1))./(Y_n(:,1)));

gr_w_i = 100.*((w_i(:,4) - w_i(:,1))./(w_i(:,1)));
gr_v_n = 100.*((v_n(:,4) - v_n(:,1))./(v_n(:,1)));

gr_L_i = 100.*((L_i(:,4) - L_i(:,1))./(L_i(:,1)));
gr_R_n = 100.*((R_n(:,4) - R_n(:,1))./(R_n(:,1)));

pdSix = fitdist(gr_Y_i,'Kernel','BandWidth',1);
x = -6:0.1:6;
ySix = pdf(pdSix,x);
plot(x,ySix,'LineWidth',1)
xlabel('Growth in local GDP (%)')
ylabel('Kernel density function')
xline(0)
avg1 = mean(gr_Y_i)
avg2 = median(gr_Y_i)
txt1 = ['Mean: ' sprintf('%.2f',avg1) '%'];
txt2 = ['Median: ' sprintf('%.2f',avg2) '%'];
text(3,0.37,txt1,'FontSize',10)
text(3,0.35,txt2,'FontSize',10)
export_fig '...\replication\outputs\gr_Y_i_distrib.pdf'

hold off

pdSix = fitdist(gr_Y_n,'Kernel','BandWidth',10);
x = -30:0.1:50;
ySix = pdf(pdSix,x);
plot(x,ySix,'LineWidth',1)
xlabel('Growth in total residential income (%)')
ylabel('Kernel density function')
xline(0)
avg1 = mean(gr_Y_n)
avg2 = median(gr_Y_n)
txt1 = ['Mean: ' sprintf('%.2f',avg1) '%'];
txt2 = ['Median: ' sprintf('%.2f',avg2) '%'];
text(30,0.032,txt1,'FontSize',10)
text(30,0.03,txt2,'FontSize',10)

export_fig '...\replication\outputs\gr_Y_n_distrib.pdf'

